/*
 * Copyright (C) 2009 Rafael Fernandes
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.phonebooksharing.android.activities.main;

import android.app.NotificationManager;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Window;
import android.widget.TabHost;

import com.phonebooksharing.android.R;
import com.phonebooksharing.android.services.LocationUpdaterService;
import com.phonebooksharing.android.services.NotSharingUpdaterService;
import com.phonebooksharing.android.util.GalleryUtilities;
import com.phonebooksharing.android.util.Global;
import com.phonebooksharing.android.widgets.drawable.FastBitmapDrawable;

public class MainContainerActivity extends TabActivity {

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        
        //makes sure the provider is triggered
        Global.loadConfig(this);
        
        if(Global.isNew) {
//        if(false) {
            EulaLicenseAgreement.showEula(this, true);
            return;
        }

        LocationUpdaterService.schedule(this);
        NotSharingUpdaterService.schedule(this);

        final Resources r = getResources();
        GalleryUtilities.noPictureBitmap = new FastBitmapDrawable(BitmapFactory.decodeResource(r, R.drawable.no_pic));
        GalleryUtilities.loadingBitmap   = new FastBitmapDrawable(BitmapFactory.decodeResource(r, R.drawable.loading));
//        ImageUtilities.addToCache(Long.MAX_VALUE,              BitmapFactory.decodeResource(r, R.drawable.no_pic));
//        ImageUtilities.addToCache(Global.WHITE_BORDER_BITMAP,  BitmapFactory.decodeResource(r, R.drawable.detail_photo_border));
//        ImageUtilities.addToCache(Global.BLUE_BORDER_BITMAP,   BitmapFactory.decodeResource(r, R.drawable.detail_photo_border_blue));
//        ImageUtilities.addToCache(Global.YELLOW_BORDER_BITMAP, BitmapFactory.decodeResource(r, R.drawable.detail_photo_border_yellow));
        
        final TabHost th = getTabHost();
        th.addTab(th.newTabSpec("t1")
                .setIndicator("Dashboard", r.getDrawable(R.drawable.dashboard))
                .setContent(new Intent(this, DashboardActivity.class)
                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));

        th.addTab(th.newTabSpec("t1")
                .setIndicator("Sharing", r.getDrawable(R.drawable.sharing))
                .setContent(new Intent(this, ShareActivity.class)));

        th.addTab(th.newTabSpec("t1")
                .setIndicator("Maps", r.getDrawable(R.drawable.maps))
                .setContent(new Intent(this, MapContainerActivity.class)));
        
        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        nm.cancel(Global.NOTIFICATION_GUID);
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
        Global.cleanUp();
    }
}